﻿@using RBAC.Web.Utilities
@using RBAC.Web.Mapper


@model RBAC.Web.Models.RoleModel

@{
      Layout = null;
    var returnList = String.Empty;
    var required = String.Empty;
    foreach (var item in Model.RequiredFields)
    {
        returnList += item + ",";
    }
    if (!String.IsNullOrEmpty(returnList))
    {
        returnList = returnList.Remove(returnList.Length - 1);
    }
}
   <!DOCTYPE html>
<html>
<head>
	<base target="_self" />
    <title></title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />    
	<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>
	<script src="@Url.Content("~/Scripts/form.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () { 

            $('.grid th').each(function () {
                if (this.innerHTML == "") {
                    this.innerHTML = "<input type='checkbox' id='chkHeader'  />";
                }
            });

            $('.grid th input:checkbox').click(function (e) {
                var table = $(e.target).closest('table');
                $('td input:checkbox', table).attr('checked', e.target.checked);
            });
        });

	


					
       
    </script>  
</head>  

<body style="padding:10px 10px 10px 10px">
  <script type="text/javascript">
        function SetOpener(@returnList) {
            @{
                var returnJSObjPattern = String.Empty;
                foreach (var item in Model.RequiredFields)
                {
                    //returnJSObjPattern += "\"" + item + "\": + " + item + " + ,";
                    returnJSObjPattern += item + ":" + item + ",";
                    required += item + "|";
                }
                if (!String.IsNullOrEmpty(returnJSObjPattern))
                {
                    returnJSObjPattern = returnJSObjPattern.Remove(returnJSObjPattern.Length - 1);
                }
                 if (!String.IsNullOrEmpty(returnJSObjPattern))
                {
                    required = required.Remove(required.Length - 1);
                }
                
            }
            if ($.browser.chrome) {
                window.opener.customReturnValue = {
                    @Html.Raw(returnJSObjPattern)
                };
            }
            else {

                window.returnValue = {
                    @Html.Raw(returnJSObjPattern)
                };
            }
            window.close();
        }

    </script>

<h2>Role</h2>
 
                @using (Html.BeginForm("User_RolePopExternalLookup", "Popup", FormMethod.Get, new { @id = "main-form" }))
            
    {
        <fieldset>
            <legend>Search</legend>
			 @Html.Hidden("required", @required)
     		
		<div class="texteditor">
        <label>RoleCode</label>
		   @Html.TextBoxFor(model => model.RoleCode)
         </div> 
            
            <div class="texteditor">
                <input type="submit" id="Search" value="Search" name="submitButton" />
            </div>
        </fieldset>
    }
@{  
    if (Model.ListOfRole != null && Model.ListOfRole.Count > 0)
    {
        var grid = new WebGrid(
            source: Model.ListOfRole, canPage: false);
        @grid.GetHtml(
        tableStyle: "tableMain grid",
        rowStyle: "row-a",
        alternatingRowStyle: "row-b",
        columns: grid.Columns(          
          grid.Column(header: "RoleCode", style: "width_10per", columnName: "RoleCode",
         
            format: item =>
            {
                string link = "<a href=\"#\" class=\"word_wrap\" onclick=\"SetOpener('{1}','{2}','{3}');\">{0}</a>";
                return Html.Raw(string.Format(link,item.RoleCode,item.Id, item.RoleCode,item.Id));
            })

										, grid.Column(header: "Role Name", style: "width_100per", columnName: "RoleName",
							format: item =>
							{
								string RoleName = "<div class=\"word_wrap\">{0}</div>";
								return Html.Raw(string.Format(RoleName, String.IsNullOrWhiteSpace(item.RoleName+"") ? "" : item.RoleName));
						 })
							, grid.Column(header: "Description", style: "width_100per", columnName: "Description",
							format: item =>
							{
								string Description = "<div class=\"word_wrap\">{0}</div>";
								return Html.Raw(string.Format(Description, String.IsNullOrWhiteSpace(item.Description+"") ? "" : item.Description));
						 })
							, grid.Column(header: "Create Date", style: "width_100per", columnName: "CreateDate",
							format: item =>
							{
								string CreateDate = "<div class=\"word_wrap\">{0}</div>";
								return Html.Raw(string.Format(CreateDate, DateTime.Parse(item.CreateDate.ToString()).ToString("dd/MM/yyyy", new System.Globalization.CultureInfo("th-TH"))));
							})

		    
        ));
    }
    else
    {
    <div class="emptyRow">No item base on search criteria that you had inputed.</div>
    
    }
 }
</body>
</html>
